﻿/*
 *Author: Jeff Liu 
 *
 *Under MIT License
 *jebberwocky@gmail.com
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Web;

namespace Citiport.Util.Google.Language
{
    /// <summary>
    /// Class for accessing Google Language API
    /// Author: Jeff
    /// Date: 04/09/2008
    /// </summary>
    public class GoogleLangAPI : WebUtil
    {
        public static String[] availibleLang;

        /// <summary>
        /// key for google language translate
        /// </summary>
        public static String GOOGLE_LANG_TRANSLATE_URL = "http://ajax.googleapis.com/ajax/services/language/translate";
        /// <summary>
        /// key for google language detect
        /// </summary>
        public static String GOOGLE_LANG_DETECT_URL = "http://ajax.googleapis.com/ajax/services/language/detect";

        public static int GOOGLE_LANG_TEXT_MAXLENGTH = 500;

        /// <summary>
        /// Translate text 
        /// </summary>
        /// <param name="text">Text to translate</param>
        /// <param name="langPair">Language pair. EX: en</param>
        /// <returns>Result from goolge service as json string</returns>
        public static String TranslateText(String text, String langPair)
        {
            text = System.Web.HttpUtility.UrlEncode(text);
            String query = GOOGLE_LANG_TRANSLATE_URL + "?v=1.0&q=" + text + "&langpair=" + langPair;
            return WebRequest(query);
        }

        /// <summary>
        /// Detect language
        /// </summary>
        /// <param name="text">Text to translate</param>
        /// <returns>Result from goolge service as json string</returns>
        public static String DetectLang(String text)
        {
            text = System.Web.HttpUtility.UrlEncode(text);
            String query = GOOGLE_LANG_DETECT_URL + "?v=1.0&q=" + text;
            return WebRequest(query);
        }
		
        [Obsolete("always return true")]
		public bool IsValidPair(String from, String to)
		{
			return true;
		}

         [Obsolete("always return true")]
        public bool IsValidLang(String lang)
        {
            return true;
        }
    }
}
